package com.ev.system.service.impl;

import com.ev.custom.vo.UpdateLogPageParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.ev.system.dao.OpLogDao;
import com.ev.system.domain.OpLogDO;
import com.ev.system.service.OpLogService;
import com.ev.system.vo.OpLogPageParam;
import com.ev.framework.utils.R;
import com.ev.apis.model.DsResultResponse;
import com.google.common.collect.Maps;


@Service
public class OpLogServiceImpl implements OpLogService {
    @Autowired
    private OpLogDao opLogDao;

    @Override
    public OpLogDO get(Long id) {
        return opLogDao.get(id);
    }

    @Override
    public List<OpLogDO> list(Map<String, Object> map) {
        return opLogDao.list(map);
    }

    @Override
    public int count(Map<String, Object> map) {
        return opLogDao.count(map);
    }

    @Override
    public int save(OpLogDO opLog) {
        return opLogDao.save(opLog);
    }

    @Override
    public int update(OpLogDO opLog) {
        return opLogDao.update(opLog);
    }

    @Override
    public int updateAll(OpLogDO opLog) {
        return opLogDao.updateAll(opLog);
    }

    @Override
    public int remove(OpLogPageParam pageParam) {
        return opLogDao.remove(pageParam);
    }

    @Override
    public int batchRemove(Long[] ids) {
        return opLogDao.batchRemove(ids);
    }

    @Override
    public R saveAndVerify(OpLogDO saveParam) {
        if (saveParam.getId() != null) {
            return opLogDao.update(saveParam) > 0 ? R.ok() : R.error();
        }
        return opLogDao.save(saveParam) > 0 ? R.ok() : R.error();
    }

    @Override
    public Map<String, Object> getById(Long id) {
        OpLogDO opLog = opLogDao.get(id);
        Map<String, Object> result = Maps.newHashMap();
        if (opLog !=null){
            result.put("data",opLog);
            return result;
        }
        return result;
    }

    @Override
    public Map<String, Object> pageList(OpLogPageParam pageParam) {
        Map<String, Object> result = Maps.newHashMap();
        List<Map<String, Object>> data = opLogDao.pageList(pageParam);
        if (data.size() > 0) {
            int total = opLogDao.pageCount(pageParam);
            result.put("data", new DsResultResponse(pageParam.getPageno(), pageParam.getPagesize(), total, data));
        }
        return result;
    }

    @Override
    public Map<String, Object> getUpdateLog(UpdateLogPageParam pageParam) {
        Map<String, Object> result = Maps.newHashMap();
        List<Map<String, Object>> data = opLogDao.getUpdateLogList(pageParam);
        if (data.size() > 0) {
            int total = opLogDao.getUpdateLogCount(pageParam);
            result.put("data", new DsResultResponse(pageParam.getPageno(), pageParam.getPagesize(), total, data));
        }
        return result;
    }

    @Override
    public Map<String, Object> getUpdateLogById(Long id) {
        return opLogDao.getUpdateLogById(id);
    }

}
